package HomeWork;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Student_Manage_Service implements Stu_Manage {
    private List<Student> students = new CopyOnWriteArrayList<>();

    @Override
    public boolean addStudent(Student student) {
        if (student != null) {
            students.add(student);
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteStudent(int studentId) {
        // 根据学生ID删除学生
        for (Student student : students) {
            if (student.getId() == studentId) {
                students.remove(student);
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean updateStudent(Student student) {
        // 更新操作的具体实现可以根据业务需求定制
        // 这里简单地添加更新逻辑
        if (student != null) {
            // 如果学生已在列表中，可以先删除再添加，或者直接更新
            students.remove(student);
            students.add(student);
            return true;
        }
        return false;
    }

    @Override
    public Student[] findAllStudents() {
        return students.toArray(new Student[0]);
    }
}
